<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/base/headcss.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>菜单管理</title>
   <link href="${path}/scripts/pagination/pagination.css"  type="text/css" rel="stylesheet" />
</head>
<body>  
		<div class="row">
		
	     <div class="col-xs-8 col-md-offset-1">
		 		<div class="page-header">
		 			<h1>菜单列表</h1>
		 			 
		 				
		 		 
		 		</div>
			    <div class="container-fluid">
				  <table class="table table-striped table-bordered table-hover">
					  <thead>
						<tr>
							<th>序号</th>
							<th>菜单名称</th>
							<th>菜单id</th>
							<th>父级菜单id</th>
							<th>排序代码</th>
							<th>操作</th>
						</tr>
					 </thead>
					 <tbody>
						<c:forEach var="entity" items="${list}"  varStatus="status">
				                <tr> 
				                    <th> ${status.count }</th>
				                    <td>${entity.name}</td>   
				                    <td>${entity.id}</td>    
				                    <td>${entity.pid}</td>          
				                  	 <td>${entity.sort}</td>
				                    <td><button class="btn btn-xs btn-info" onclick="edit(${entity.id});">
											<i class="icon-edit bigger-120"></i>
										</button>
										<button class="btn btn-xs btn-danger" onclick="deleteResource(${entity.id});">
											<i class="icon-trash bigger-120"></i>
										</button>	
										<button class="btn btn-sm btn-primary"
										 onclick="add('${entity.id}','${entity.sort}');">新增</button>
									</td>
				                </tr>
				         </c:forEach>	
				      </tbody>
			       </table>
			     </div>
		         <div id="pager">
		         </div>
	        </div>
	    </div>
        <!--分页 -->
        <script type="text/javascript" src="<c:url value="/scripts/jQuery/jquery-1.10.2.min.js"/>" ></script>
        <script type="text/javascript" src="<c:url value="/scripts/pagination/jquery.pagination.js"/>" ></script>
           <script type="text/javascript">
           //初始化分页组件
           var count=${page.total};//总数
           var size=${page.pageSize};//每页显示多少
           var pageNO=${page.pageNum};//第几页
           $("#pager").pagination(count-1, {
               items_per_page:size,
               current_page:pageNO-1,
               next_text:"下一页",
               prev_text:"上一页",
               num_edge_entries:0,
               load_first_page:false,
              callback:handlePaginationClick
            });
           
           //回调方法
           function handlePaginationClick(new_page_index, pagination_container){
               location.href="list?pageNO="+(new_page_index+1);
           }
           function edit(id){
   
           }
           function add(pid,sort){
        	    window.open ("${path}/resource/add?pid="+pid+"&sort="+sort, " 新增菜单", "height=650, width=800, top=200, left=800, toolbar=no"); 
           }
           function deleteResource(id){
        	   if(confirm("是否确认删除菜单 ")){
        		   $.ajax({
        	            //几个参数需要注意一下
        	                type: "GET",//方法类型
        	                dataType: "text",//预期服务器返回的数据类型
        	                url: "<c:url value='/resource/delete'/>" ,//url
        	                data: {'id':id},
        	                success: function (data) {
        	                    if (data == "success") {
        	                        alert("删除成功");
        	                        location.reload();
        	                    }else{
        	                    	alert("删除失败");
        	                    }
        	                },
        	                error : function() {
        	                    alert("删除失败！");
        	                }
        	            });
        	   }   
           }
        </script>
	
</body>
</html>